﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Day.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class SepController : ControllerBase
    {
        /// <summary>
        /// 获取字符串的长度
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult StringLength()
        {
            string a = "一般情况下值类型存在它声明的地方";
            int s = a.Length;
            return Ok(s);
        }
        /// <summary>
        /// 查找该字第一个匹配 下标
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult StringIndexOf()
        {
            string a = "一般情况下值类型存在类声明的地方";
            int s = a.IndexOf("类");
            return Ok(s);
        }
        /// <summary>
        /// 查找该字最后第一个匹配 下标
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult StringLastIndexOf()
        {
            string a = "一般情况下它类型存在它声明的地方";
            int s = a.LastIndexOf("它");
            return Ok(s);
        }
        /// <summary>
        /// 截取字符串
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult StringSubstring()
        {
            string a = "一般情况下它类型存在它声明的地方";
            var s = a.Substring(0,6);
            return Ok(s);
        }
        /// <summary>
        /// 分割字符串
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult StringSplit()
        {
            string a = "一般情况,下它类型存,在它声明的,地方";
            var s = a.Split(',');
            return Ok(s);
        }
        /// <summary>
        /// 大写
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult StringToUpper()
        {
            string a = "data";
            var s = a.ToUpper();
            return Ok(s);
        }
        /// <summary>
        /// 小写
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult StringToLower()
        {
            string a = "DATE";
            var s = a.ToLower();
            return Ok(s);
        }
        /// <summary>
         /// 删除空白
         /// </summary>
         /// <returns></returns>
        [HttpGet]
        public IActionResult StringTrim()
        {
            string a = "  王五";
            var s = a.Trim();
            return Ok(s);
        }

        /// <summary>
        /// 判断是否为空
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult StringIsNullOrEmpty(string? name)
        {
            if (string.IsNullOrEmpty(name))
            {
                return Ok("空");
            }
            else
            {
                return Ok("不为空");
            }
        }
        /// <summary>
        /// 判断是否为空
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult StringIsNullOrWhiteSpace(string? name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                return Ok("空");
            }
            else
            {
                return Ok("不为空");
            }
        }

    }
}
